/*
 * @Author: CodeHare
 * @Date: 2023-09-27 10:59:53
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-25 14:13:16
 * @Description: 站点数据总览页
 */
import 'package:get/get.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/utils/enums.dart';

class SiteStatisDataModel {
  SiteStatisDataModel();
  List chartLineColor = [
    '#FF7070', //市电
    '#FAC958', //光伏
    '#0984F9', //储能
    '#01D57D', //充电桩
    '#67D7FC', //其他负载
  ];

  List chartLineTitles = [
    ResKey.deviceElectricSupply.tr, //市电
    ResKey.photovoltaic.tr, //光伏
    ResKey.energyStorage.tr, //储能
    ResKey.chargingStation.tr, //充电桩
    ResKey.deviceOtherLoad.tr, //其他负载
  ];

  List<Map<String, dynamic>> chartShowTitles = [];
  List<Map<String, dynamic>> chartShowDetailTitles = [];
  List<Map<String, dynamic>> showElectricityTitles = [];
  List<String> paramList = [
    ResKey.chargingCapacity.tr,
    'siteMonitor.disChargingCapacity'.tr,
    '充电费用',
    '放电收入',
    ResKey.income.tr,
  ];
  List chartBarColor = [
    '#8080FF', //光伏自用
    '#FAC958', //光伏发电
    '#FF7070', //市电
    '#0984F9', //储能充电
    '#F79631', //储能放电
    '#01D57D', //充电桩
    '#67D7FC', //其他负载
  ];

  List chartBarTitles = [
    ResKey.pvSelfConsumption.tr,
    ResKey.siteSettingObserverPhotovoltaicQuantity.tr,
    'siteMonitor.mainsCapacity'.tr,
    ResKey.siteSettingObserverStoreChargePower.tr,
    ResKey.siteSettingObserverStoreDischargePower.tr,
    ResKey.siteSettingObserverChargePower.tr,
    ResKey.siteSettingObserverLoadPower.tr,
  ];
  List <String> siteOverviewTitles = [
    ResKey.totalRevenue.tr,//总收益
    ResKey.siteSettingObserverElectricityConsumption.tr,//市电供电量
    ResKey.mainsFeederPower.tr,//市电馈网电量
    ResKey.siteSettingObserverPhotovoltaicQuantity.tr,//光伏发电量
    'device.pvRevenue'.tr,//光伏收益
    'device.selfUseRate'.tr,//自发自用率
    'siteMonitor.selfSufficiencyRatio'.tr,//自给自足率
    ResKey.siteSettingObserverStoreChargePower.tr,//储能充电量
    ResKey.siteSettingObserverStoreDischargePower.tr,//储能放电量
    'device.storageCharge'.tr,//储能充电收益
    'device.storageDischarge'.tr,//储能放电收益
    'device.storageRevenue'.tr,//储能收益
    ResKey.siteSettingObserverChargePower.tr,//充电桩充电量
    ResKey.chargingPileOrderQuantity.tr,//充电桩订单量
    'device.chargingRevenue'.tr,//充电桩收益
    'siteMonitor.otherLoadElectricConsumption'.tr,//其他负载供电量
  ];


  /// 时间变更数量
  int changeNum = 0;

  /// Tab切换控制变量
  bool activeDay = true;
  bool activeMonth = false;
  bool activeYear = false;
  bool activeAccumulate = false;
  DateTimePickerMode pickerMode = DateTimePickerMode.day;
  double totalIncome = 0;

  /// 时间选择
  // double timeButtonWidth = 120.w;

  /// 图表横轴切割
  int needSplitTimeAxis = 0;

  /// 功率表
  /// 光伏发电功率
  List<PvPower> pvPower = [];

  /// 光伏发电功率图表传入值
  List<List> pvDataList = [];

  /// 储能功率
  List<EsPower> esPower = [];

  /// 储能功率图表传入值
  List<List> esDataList = [];

  /// 能量表
  /// 储能充电量
  List<Charge> charge = [];

  /// 储能充电量图表传入值
  List<List> chargeList = [];

  /// 储能放电量
  List<Discharge> discharge = [];

  /// 储能放电量图表传入值
  List<List<dynamic>> dischargeList = [];

  /// 光伏发电量
  List<PvPowerGeneration> pvPowerGeneration = [];

  /// 光伏发电量图表传入值
  List<List<dynamic>> pvPowerGenerationList = [];

  /// 收益表
  /// 收益
  List<Income> income = [];

  /// 收益图表值
  List<List> incomeList = [];
}

/// 站点内统计数据（来源于后台）
class StatisticsWithinTheSite {
  /// 储能充、放电功率  大于0充电  小于0放电
  List<EsPower>? esPower;

  /// 充电桩功率，示例：-
  List<CsPower>? csPower;

  /// 光伏功率，示例：-
  List<PvPower>? pvPower;

  /// 充电，示例：-
  List<Charge>? charge;

  /// 储能放电，示例：-
  List<Discharge>? discharge;

  /// 充电桩用电，示例：-
  List<PowerConsumption>? powerConsumption;

  /// 光伏发电，示例：-
  List<PvPowerGeneration>? pvPowerGeneration;

  ///收益集合
  List<Income>? income;

  /// 总收益
  double? totalIncome;

  ///光伏发电总量（能量图表发电量值）
  double? totalPowerGeneration = 0.0;

  StatisticsWithinTheSite({
    this.charge,
    this.csPower,
    this.discharge,
    this.esPower,
    this.powerConsumption,
    this.pvPower,
    this.pvPowerGeneration,
    this.income,
    this.totalIncome,
    this.totalPowerGeneration,
  });

  factory StatisticsWithinTheSite.fromJson(Map<String, dynamic> json) =>
      StatisticsWithinTheSite(
        charge:
            List<Charge>.from(json["charge"].map((x) => Charge.fromJson(x))),
        csPower:
            List<CsPower>.from(json["csPower"].map((x) => CsPower.fromJson(x))),
        discharge: List<Discharge>.from(
            json["discharge"].map((x) => Discharge.fromJson(x))),
        esPower:
            List<EsPower>.from(json["esPower"].map((x) => EsPower.fromJson(x))),
        powerConsumption: List<PowerConsumption>.from(
            json["powerConsumption"].map((x) => PowerConsumption.fromJson(x))),
        pvPower:
            List<PvPower>.from(json["pvPower"].map((x) => PvPower.fromJson(x))),
        pvPowerGeneration: List<PvPowerGeneration>.from(
            json["pvPowerGeneration"]
                .map((x) => PvPowerGeneration.fromJson(x))),
        income: List<Income>.from(json["income"].map((x) => Income.fromMap(x))),
        totalIncome: json["totalIncome"]?.toDouble(),
        totalPowerGeneration: json["totalPowerGeneration"]?.toDouble(),
      );
}

/// 充电
class Charge {
  ///充电金额，示例：0
  num amount;

  ///充电量，示例：0
  num electricity;

  ///充电时间，示例：2023-01
  String timeDimension;

  /// 获得时间 2023-12-15 23:30:00 => 23:30:00
  String get getTime {
    return timeDimension.substring(11, 16);
  }

  /// 获得月日间隔 2023-12-27 => 12-27
  String get getMonthDayDimension {
    return timeDimension.substring(5, 10);
  }

  /// 获得时间间隔-完整来自后端数据
  String get getTimeDimension {
    return timeDimension;
  }

  Charge({
    required this.amount,
    required this.electricity,
    required this.timeDimension,
  });

  factory Charge.fromJson(Map<String, dynamic> json) => Charge(
        amount: json["amount"],
        electricity: json["electricity"],
        timeDimension: json["timeDimension"],
      );

  Map<String, dynamic> toMap() => {
        "amount": amount,
        "electricity": electricity,
        "timeDimension": timeDimension,
      };
}

/// 充电桩功率
class CsPower {
  ///值，示例：0
  double? doubleVal;

  ///时间，示例：2023-08-01 23:55:00
  String? eventTs;

  CsPower({
    this.doubleVal,
    this.eventTs,
  });

  factory CsPower.fromJson(Map<String, dynamic> json) => CsPower(
        doubleVal: json["doubleVal"],
        eventTs: json["eventTs"],
      );

  Map<String, dynamic> toMap() => {
        "doubleVal": doubleVal,
        "eventTs": eventTs,
      };
}

/// 储能放电
class Discharge {
  ///放电金额，示例：0
  num amount;

  ///放电量，示例：0
  num electricity;

  ///放电时间，示例：2023-01
  String timeDimension;

  /// 获得时间 2023-12-15 23:30:00 => 23:30:00
  String get getTime {
    return timeDimension.substring(11, 16);
  }

  /// 获得月日间隔 2023-12-27 => 12-27
  String get getMonthDayDimension {
    return timeDimension.substring(5, 10);
  }

  /// 获得时间间隔-完整来自后端数据
  String get getTimeDimension {
    return timeDimension;
  }

  Discharge({
    required this.amount,
    required this.electricity,
    required this.timeDimension,
  });

  factory Discharge.fromJson(Map<String, dynamic> json) => Discharge(
        amount: json["amount"],
        electricity: json["electricity"],
        timeDimension: json["timeDimension"],
      );

  Map<String, dynamic> toMap() => {
        "amount": amount,
        "electricity": electricity,
        "timeDimension": timeDimension,
      };
}

/// 储能功率
class EsPower {
  ///值，示例：0
  double? doubleVal;

  ///时间，示例：2023-08-01 23:55:00
  String? eventTs;

  EsPower({
    this.doubleVal,
    this.eventTs,
  });

  String get getTime {
    if (eventTs == null) {
      return '';
    } else {
      return eventTs!.substring(11, 16);
    }
  }

  factory EsPower.fromJson(Map<String, dynamic> json) => EsPower(
        doubleVal: json["doubleVal"],
        eventTs: json["eventTs"],
      );

  Map<String, dynamic> toMap() => {
        "doubleVal": doubleVal,
        "eventTs": eventTs,
      };
}

/// 充电桩用电
class PowerConsumption {
  ///用电金额，示例：0
  num amount;

  ///用电量，示例：0
  num electricity;

  ///用电时间，示例：2023-01
  String timeDimension;

  PowerConsumption({
    required this.amount,
    required this.electricity,
    required this.timeDimension,
  });

  factory PowerConsumption.fromJson(Map<String, dynamic> json) =>
      PowerConsumption(
        amount: json["amount"],
        electricity: json["electricity"],
        timeDimension: json["timeDimension"],
      );

  Map<String, dynamic> toMap() => {
        "amount": amount,
        "electricity": electricity,
        "timeDimension": timeDimension,
      };
}

/// 光伏功率
class PvPower {
  ///值，示例：0
  double? doubleVal;

  ///时间，示例：2023-08-01 23:55:00
  String? eventTs;

  PvPower({
    this.doubleVal,
    this.eventTs,
  });

  String get getTime {
    if (eventTs == null) {
      return '';
    } else {
      return eventTs!.substring(11, 16);
    }
  }

  factory PvPower.fromJson(Map<String, dynamic> json) => PvPower(
        doubleVal: json["doubleVal"],
        eventTs: json["eventTs"],
      );

  Map<String, dynamic> toMap() => {
        "doubleVal": doubleVal,
        "eventTs": eventTs,
      };
}

/// 光伏发电
class PvPowerGeneration {
  ///发电金额，示例：0
  num amount;

  ///光伏发电量，示例：0
  num electricity;

  ///光伏发电时间，示例：2023-01
  String timeDimension;

  /// 获得时间 2023-12-15 23:30:00 => 23:30:00
  String get getTime {
    return timeDimension.substring(11, 16);
  }

  /// 获得月日间隔 2023-12-27 => 12-27
  String get getMonthDayDimension {
    return timeDimension.substring(5, 10);
  }

  /// 获得时间间隔-完整来自后端数据
  String get getTimeDimension {
    return timeDimension;
  }

  PvPowerGeneration({
    required this.amount,
    required this.electricity,
    required this.timeDimension,
  });

  factory PvPowerGeneration.fromJson(Map<String, dynamic> json) =>
      PvPowerGeneration(
        amount: json["amount"],
        electricity: json["electricity"],
        timeDimension: json["timeDimension"],
      );

  Map<String, dynamic> toMap() => {
        "amount": amount,
        "electricity": electricity,
        "timeDimension": timeDimension,
      };
}

class Income {
  /// 收益
  num amount;

  /// 时间
  String timeDimension;

  /// 获得时间 2023-12-15 23:30:00 => 23:30:00
  String get getTime {
    return timeDimension.substring(11, 16);
  }

  /// 获得月日间隔 2023-12-27 => 12-27
  String get getMonthDayDimension {
    return timeDimension.substring(5, 10);
  }

  /// 获得时间间隔-完整来自后端数据
  String get getTimeDimension {
    return timeDimension;
  }

  Income({
    required this.amount,
    required this.timeDimension,
  });

  factory Income.fromMap(Map<String, dynamic> json) => Income(
        amount: json["amount"],
        timeDimension: json["timeDimension"],
      );

  Map<String, dynamic> toMap() => {
        "amount": amount,
        "timeDimension": timeDimension,
      };
}
